﻿using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Threading;
using Themes;

namespace CommonModule.ViewModels
{
    public class HeaderViewModel : BindableBase
    {
        /// <summary>
        /// 切换主题
        /// </summary>
        public DelegateCommand SwitchThemeCommand { get; }

        private bool _isDark = false;

        /// <summary>
        /// 定时器
        /// </summary>
        private readonly DispatcherTimer _timer;



        private string _systemTitle = "设备管理系统";
        public string SystemTitle
        {
            get => _systemTitle;
            set => SetProperty(ref _systemTitle, value);
        }

        private string _currentTime;
        public string CurrentTime
        {
            get => _currentTime;
            set => SetProperty(ref _currentTime, value);
        }

        public HeaderViewModel()
        {
            // 初始化时间
            UpdateTime();

            // 启动定时器，每秒更新一次
            _timer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(1)
            };
            _timer.Tick += (s, e) => UpdateTime();
            _timer.Start();

            SwitchThemeCommand = new DelegateCommand(SwitchTheme);
        }

        private void SwitchTheme()
        {
            _isDark = !_isDark;
            var themeName = _isDark ? "DarkTheme" : "LightTheme";
            ThemeManager.ApplyTheme(themeName);
        }

        private void UpdateTime()
        {
            CurrentTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }
    }
}